package com.longcai.service.impl.homepage;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.longcai.bean.ApiResult;
import com.longcai.entity.homepage.ClyjHeadlines;
import com.longcai.mapper.homepage.ClyjHeadlinesMapper;
import com.longcai.service.homepage.ClyjHeadlinesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 平台头条 服务实现类
 * </p>
 *
 * @author LWK
 * @since 2019-03-20
 */
@Service
public class ClyjHeadlinesServiceImpl extends ServiceImpl<ClyjHeadlinesMapper, ClyjHeadlines> implements ClyjHeadlinesService {

    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private ClyjHeadlinesMapper clyjHeadlinesMapper;

    /**
     * 新闻详情
     *
     * @param id
     * @return
     */
    @Override
    public ApiResult getdetails(String id) {
        try {
            QueryWrapper<ClyjHeadlines> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id", id);
            queryWrapper.eq("status", 0);
            ClyjHeadlines clyjHeadlines = this.clyjHeadlinesMapper.selectOne(queryWrapper);
            clyjHeadlines.setShowTime(clyjHeadlines.getShowTime() + 1);
            this.clyjHeadlinesMapper.updateById(clyjHeadlines);
            logger.debug("查询成功", clyjHeadlines);
            return ApiResult.success(clyjHeadlines);
        } catch (Exception e) {
            logger.error("查询失败");
            e.printStackTrace();
            return ApiResult.fail("查询失败" + e.getMessage());
        }
    }
}
